#!/bin/bash

set -e

PROJECT_DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$PROJECT_DIR"

echo "🚀 启动疫苗预约系统..."

# 检查 Docker 是否运行
if ! docker info > /dev/null 2>&1; then
    echo "❌ 错误: Docker 未运行，请先启动 Docker Desktop"
    exit 1
fi

# 启动 Docker Compose 服务
echo "📦 启动 MySQL 和 Redis 容器..."
docker compose up -d

# 等待 MySQL 启动
echo "⏳ 等待 MySQL 启动..."
sleep 10

# 检查容器状态
echo "📊 当前容器状态："
docker compose ps

echo ""
echo "✅ 数据库服务已就绪！"
echo "   - MySQL: localhost:3306  (root / 123456)"
echo "   - Redis: localhost:6379  (密码 123456)"
echo ""
echo "🚀 接下来将启动 Spring Boot（按 Ctrl+C 可停止）。"
echo "   若要关闭 MySQL/Redis，请另开终端执行 ./stop.sh"
echo ""

# 配置 JDK
export JAVA_HOME="$HOME/java/jdk-11.0.29+7/Contents/Home"
export PATH="$JAVA_HOME/bin:$PATH"



# 前台启动 Spring Boot
mvn spring-boot:run

